package org.example.springgobang.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.springgobang.model.User;

@Mapper
public interface UserMapper {
    //插入一个新用户,用于注册功能
    @Insert("insert into user (username,password,score,total_count,win_count) " +
            "values (#{username},#{password},1000,0,0)")
    void insertUser(User user);

    //根据用户名，来查询用户的详细信息，用于登录
    @Select("select * from user where username=#{username}")
    User selectByName(String username);

    @Update("update user set score=score+30,total_count=total_count+1,win_count=win_count+1 where user_id=#{userId}")
    void userWin(int userId);

    @Update("update user set score=score-30,total_count=total_count+1 where user_id=#{userId}")
    void userLose(int userId);
}
